#include "registerdialog.h"
#include "ui_registerdialog.h"
#include "global.h"


RegisterDialog::RegisterDialog(QWidget *parent)
    : QDialog(parent)
    , ui(new Ui::RegisterDialog)
{
    ui->setupUi(this);
    initWidget();
    initSignal();
}

RegisterDialog::~RegisterDialog()
{
    delete ui;
}

void RegisterDialog::initWidget()
{
    ui->passwd_edit->setEchoMode(QLineEdit::Password);
    ui->confirm_edit->setEchoMode(QLineEdit::Password);

    ui->err_tip->setProperty("state","normal");
    repolish(ui->err_tip);
}

void RegisterDialog::initSignal()
{
    connect(ui->get_code_btn,&QPushButton::clicked,this,&RegisterDialog::on_getCode);
}

void RegisterDialog::on_getCode()
{
    auto email = ui->code_edit->text();
    QRegularExpression regex(R"((\w+)(\.|_)?(\w*)@(\w+)(\.(\w+))+)");

    bool match = regex.match(email).hasMatch();
    if(match)
    {

    }
    else
    {
        showTip(tr("邮箱地址不正确"));
    }
}

void RegisterDialog::showTip(QString _msg, bool _falg)
{
    if(_falg)
    {
        ui->err_tip->setProperty("state","nomal");
    }
    else
    {
        ui->err_tip->setProperty("state","err");
    }
    ui->err_tip->setText(_msg);
    repolish(ui->err_tip);
}
